package lgkj.meicqt20.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import lgkj.meicqt20.R;

/**
 * Created by Administrator on 2017/8/8 0008.
 */

public class VidoesNumAdapter extends BaseAdapter {
    private List<String> mdata;
    private Context mContext;

    public void setmPositon(int mPositon) {
        this.mPositon = mPositon;
    }

    private int mPositon = 0;

    public void setData(List<String> data) {
        if (data != null) {
            this.mdata = data;
        }
    }

    public VidoesNumAdapter(Context context) {
        this.mContext = context;
        mdata = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return mdata.size();
    }

    @Override
    public String getItem(int i) {

        if ((i + 1) > mdata.size()) {
            return "";
        } else {
            return mdata.get(i);
        }
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        HolderView holderView = null;

        if (view == null) {
            holderView = new HolderView();
            view = LayoutInflater.from(mContext).inflate(R.layout.item_vidoes_num, null);
            holderView.tv_num = view.findViewById(R.id.tv_num);
            view.setTag(holderView);
        } else {
            holderView = (HolderView) view.getTag();
        }
        holderView.tv_num.setText((i + 1) + "");
        holderView.tv_num.setTag(mdata.get(i));
        if (mPositon == i) {
            holderView.tv_num.setBackgroundColor(0xFF35b135);
        } else {
            holderView.tv_num.setBackgroundColor(0);
        }

        return view;
    }

    class HolderView {
        TextView tv_num;
    }
}
